#include "setAlejar.h"
#include "Seek.h"
#include "Arrive.h"
#include "Face.h"
#include "Separation.h"
#include "../Steering.h"
#include "../Character.h"
#include "../Obstacle.h"

setAlejar::setAlejar(Character * _character,Character* _player,vector<Character*>* ch,vector<Obstacle*>* ob){
  player = _player;
  character = _character;
  //-  Aqui introducimos el comportamiento Seek en la 1era. posicion -//
//Seek * seek = new Seek(); 
  Arrive * seek = new Arrive();
  seek->SetCharacter(_character);
  seek->SetTarget(_player);
  set.push_back(seek);
  //-  Aqui introducimos el comportamiento Face en la 2da. posicion -//
  Face * face = new Face();
  face->SetCharacter(_character);
  face->SetTarget(_player);
  set.push_back(face);
  //-  Aqui introducimos el comportamiento Separation en la 3era. posicion -//
  Separation * sep = new Separation(ch,ob);
  sep->SetCharacter(_character);
  sep->SetTarget(_player);
  set.push_back(sep);
}

Steering* setAlejar::getSteering(){
  Steering* ret = new Steering();
  for(int i = 0 , n = set.size()-1; i < n ; i++){
    Steering* auxS = set[i]->getSteering();
    restarVectores(ret->linear,auxS->linear,ret->linear);
    ret->angular-=auxS->angular;
  }
  Steering* auxS = set[set.size()-1]->getSteering();
  sumarVectores(ret->linear,auxS->linear,ret->linear);
  ret->angular-=auxS->angular;
  return ret;
}

void setAlejar::SetTarget(Character* t){
  for (int i = 0, n = set.size(); i < n ;i++)
    set[i]->SetTarget(t);
}

const Character* setBehavior::GetCharacter(){
  return set[0]->GetCharacter();
}
